//
//  IWPopView.m
//  SINA
//
//  Created by 王相超 on 16/3/28.
//  Copyright © 2016年 chuanzhi. All rights reserved.
//

#import "IWPopView.h"

@interface IWPopView()

@property(strong ,nonatomic)UIImageView *imageView1;

@end

@implementation IWPopView

-(instancetype)initWithCustomView:(UIView *)customView{
    
    if (self = [super init]) {
        
        self.size = [UIScreen mainScreen].bounds.size;
        [self addTarget:self action:@selector(hide:) forControlEvents:UIControlEventTouchUpInside];
        
        UIImageView *imageView = [[UIImageView alloc] init];
        UIImage *image = [UIImage imageNamed:@"popover_background"];
        imageView.image =[image stretchableImageWithLeftCapWidth:image.size.width/2 topCapHeight:image.size.height/2];
        imageView.size = CGSizeMake(customView.width+10, customView.height+20);
        
        customView.x = 5;
        customView.y = 12;
        
        [imageView addSubview:customView];
        
        [self addSubview:imageView];
        
        self.imageView1 = imageView;
        
    }
    
    return self;
    
}


-(void)showWithView:(UIView *)targetView{
    
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    
    CGRect rect = [targetView convertRect:targetView.bounds toView:window];
    
    self.imageView1.centerX = CGRectGetMidX(rect);
    self.imageView1.y = CGRectGetMaxY(rect);
    
    [window addSubview:self];
}



-(void)hide:(UIButton *)btn{
    
    [self removeFromSuperview];
}

@end
